<?php

namespace App\Services\MockUser;

use App\Models\User;
use Illuminate\Support\Facades\Log;

abstract class MockUser
{
	/**
	 * Mock name
	 * @return string
	 */
	abstract protected function name() : string ;
	abstract protected function phone() : string ;
	
	protected function getExisting()
	{
		return User::where('is_mock', true)
			->where('mock_name', $this->name())
			->where('phone', $this->phone())
			->where('grade', 'vip')
			->first();
	}
	
	protected function mockUser()
	{
		return User::create([
			'is_mock' => true,
			'mock_name' => $this->name(),
			'grade' => 'vip',
			'phone' => $this->phone(),
			'name' => $this->name(),
			'password' => bcrypt(time()),
		]);
	}
	
	protected function mockedUser()
	{
		$mockedUser = $this->getExisting();
		
		if ($mockedUser) return $mockedUser;
		
		return $this->mockUser();
	}
	
	protected function robot()
	{
		Log::debug('Get mocked gold storm user');
		return $this->mockedUser();
	}
}
